package cn.lzg.common.core.model;

import cn.lzg.common.core.serial.Serializer;

/**
 * 结果对象：请求处理结束后，控制管理层 根据响应对象封装Result 返回
 * @author LizG
 *
 * @param <T> 消息对象（登陆响应对象，私聊响应对象...）
 */
public class Result<T extends Serializer> {
	/*
	 * 结果码
	 */
	private int resultCode;
	
	/*
	 * 结果内容
	 */
	private T content;
	
	/*
	 * 请求成功，根据content 封装Result
	 */
	public static <T extends Serializer> Result<T> SUCCESS(T content) {
		Result<T> result = new Result<>();
		result.setResultCode(ResultCode.SUCCESS);
		result.setContent(content);
		return result;
	}
	
	/*
	 * 请求成功，封装Result,无content
	 */
	public static <T extends Serializer> Result<T> SUCCESS(){
		Result<T> result = new Result<>();
		result.setResultCode(ResultCode.SUCCESS);
		return result;
	}
	
	/*
	 * 请求失败
	 */
	public static <T extends Serializer> Result<T> ERROR(int resultCode){
		Result<T> result = new Result<>();
		result.setResultCode(resultCode);
		return result;
	}
	
	/*
	 * 
	 */
	public static <T extends Serializer> Result<T> valueOf(int resultCode,T content){
		Result<T> result = new Result<>();
		result.setResultCode(resultCode);
		result.setContent(content);
		return result;
	}

	public int getResultCode() {
		return resultCode;
	}

	public void setResultCode(int resultCode) {
		this.resultCode = resultCode;
	}

	public T getContent() {
		return content;
	}

	public void setContent(T content) {
		this.content = content;
	}
	
	public boolean isSuccess(){
		return this.resultCode == ResultCode.SUCCESS;
	}
}
